<?php

/**
 * @category   Oos
 * @package    Oos_Site_Extension
 * @license    New BSD License
 */

/**
 * @see Zend_Gdata_Extension
 */
require_once 'Zend/Gdata/Extension.php';


class Oos_Site_Extension_Area extends Zend_Gdata_Extension
{

    protected $_rootNamespace = 'oos';
    protected $_rootElement = 'area';
    protected $_text = null;
    protected $_slug = null;

    /**
     * Constructs a new Oos_Site_Extension_Area object.
     * @param string $value (optional) The text content of the element.
     */
    public function __construct($value = null, $slug = null)
    {
        foreach (Oos_Site::$namespaces as $nsPrefix => $nsUri) {
            $this->registerNamespace($nsPrefix, $nsUri);
        }
        parent::__construct();
        $this->_text = $value;
		$this->_slug = $slug;
    }

    /**
     * Retrieves a DOMElement which corresponds to this element and all
     * child properties.  This is used to build an entry back into a DOM
     * and eventually XML text for sending to the server upon updates, or
     * for application storage/persistence.
     *
     * @param DOMDocument $doc The DOMDocument used to construct DOMElements
     * @return DOMElement The DOMElement representing this element and all
     * child properties.
     */
    public function getDOM($doc = null)
    {
        $element = parent::getDOM($doc);
        if ($this->_slug != null) {
            $element->setAttribute('slug', $this->_slug);
        }
        return $element;
    }

    /**
     * Given a DOMNode representing an attribute, tries to map the data into
     * instance members.  If no mapping is defined, the name and value are
     * stored in an array.
     *
     * @param DOMNode $attribute The DOMNode attribute needed to be handled
     */
    protected function takeAttributeFromDOM($attribute)
    {
        switch ($attribute->localName) {
	case 'slug':
  	    $this->_slug = $attribute->nodeValue;
	    break;
        default:
            parent::takeAttributeFromDOM($attribute);
        }
    }

    /**
     * Get the value for this element's value attribute.
     *
     * @return string The value associated with this attribute.
     */
    public function getText()
    {
        return $this->_text;
    }

    /**
     * Set the value for this element's value attribute.
     *
     * @param string $value The desired value for this attribute.
     */
    public function setText($value)
    {
        $this->_text = $value;
        return $this;
    }

    public function setSlug($value)
    {
      $this->_slug = $value;
    }
    public function getSlug()
    {
      return $this->_slug;
    }
    /**
     * Magic toString method allows using this directly via echo
     * Works best in PHP >= 4.2.0
     */
    public function __toString()
    {
        return $this->_text;
    }

    public function getAsArray()
    {
    	return array(name => $this->_text, slug => $this->_slug);
    }
}
